/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { DiffUtil } from '../../../../../src/base/internal/snapshot/comparator/filesystem-snapshot-diff-util';
import { DirectorySnapshot } from '../../../../../src/base/internal/snapshot/core/directory-snapshot';
import {
  FileSystemSnapshotNameComparator
} from '../../../../../src/base/internal/snapshot/comparator/filesystem-snapshot-detail-comparator';

describe('test snapshot comparator', () => {

  test('test snapshot detail diff comparator', () => {
    const oldRootSnapshot = new DirectorySnapshot('a');
    const oldChild1 = new DirectorySnapshot('b');
    const oldChild2 = new DirectorySnapshot('c');
    oldRootSnapshot.children.push(oldChild1, oldChild2);

    const newRootSnapshot = new DirectorySnapshot('b');
    const newChild1 = new DirectorySnapshot('c');
    const newChild2 = new DirectorySnapshot('d');
    newRootSnapshot.children.push(newChild1, newChild2);

    const fileSnapshotDetailDiff = DiffUtil.diffWithDetail(oldRootSnapshot, newRootSnapshot,
      new FileSystemSnapshotNameComparator());
    const removedNodes = fileSnapshotDetailDiff.removedNodes;
    const updatedNodes = fileSnapshotDetailDiff.updatedNodes;
    const addedNodes = fileSnapshotDetailDiff.addedNodes;

    expect(removedNodes.length).toBe(1);
    expect(removedNodes[0].name).toBe('a');
    expect(updatedNodes.length).toBe(2);
    expect(updatedNodes[0].name).toBe('b');
    expect(updatedNodes[1].name).toBe('c');
    expect(addedNodes.length).toBe(1);
    expect(addedNodes[0].name).toBe('d');
  });
});
